package thread;

public class ThreadDemo4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(){ //写{}的意思是要定义一个类，且这个新的类继承自Thread
                                //此处{}中定义子类的属性和方法，此时最主要的目的就是重写run方法
            @Override
            public void run() {
                super.run();
                while (true){
                    System.out.println("hello run");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        t.start();

        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
